package com.qsmx.qingqiuticket.app.util;

import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;

import com.qsmx.qingqiuticket.app.R;

import java.util.HashMap;

public class SoundPlayUtils {
    // SoundPool对象
    public static SoundPool mSoundPlayer = new SoundPool(10,
            AudioManager.STREAM_SYSTEM, 5);
    public static SoundPlayUtils soundPlayUtils;
    public static HashMap<Integer, Integer> mSPMap;
    // 上下文
    static Context mContext;

    /**
     * 初始化
     *
     * @param context
     */
    public static SoundPlayUtils init(Context context) {
        if (soundPlayUtils == null) {
            soundPlayUtils = new SoundPlayUtils();
        }

        // 初始化声音
        /**
         */
        mContext = context;
        mSPMap = new HashMap<Integer, Integer>();
        mSPMap.put(1, mSoundPlayer.load(mContext, R.raw.please_check_package, 1));// 1)
        mSPMap.put(2, mSoundPlayer.load(mContext, R.raw.please_show_qr_code, 1));// 1)
        mSPMap.put(3, mSoundPlayer.load(mContext, R.raw.please_check_ticket, 1));// 1)
        mSPMap.put(4, mSoundPlayer.load(mContext, R.raw.print_now, 1));// 1)
//        mSPMap.put(5, mSoundPlayer.load(mContext, R.raw.show_code_or_input_code_tips, 1));// 1)
//        mSPMap.put(6, mSoundPlayer.load(mContext, R.raw.please_check_card_and_out_coin, 1));// 1)
//        mSPMap.put(7, mSoundPlayer.load(mContext, R.raw.card_out_tips, 1));// 1)
//        mSPMap.put(8, mSoundPlayer.load(mContext, R.raw.please_show_pay_code, 1));// 1)
//        mSPMap.put(9, mSoundPlayer.load(mContext, R.raw.please_show_mem_code, 1));// 1)

        return soundPlayUtils;
    }

    /**
     * 播放声音
     *
     * @param soundID
     */
    public static int play(int soundID) {
        int lastId = mSoundPlayer.play(mSPMap.get(soundID), 1, 1, 0, 0, 1);
        return lastId;
    }


    /**
     * 释放音效资源
     */
    public static void release(int i) {
        mSoundPlayer.stop(i);
    }

}